package com.wontube.core.conf.dogs;

import com.wontube.core.conf.Proxy;

/**
 * @author yuechao
 *
 */
public final class ProxyWatchDog extends FileWatchDog {
	/**
	 * @param filename
	 */
	public ProxyWatchDog(String confPath) {
		super(confPath);
	}

	/* 
	 * @see core.pub.FileWatchDog#doOnChange()
	 */
	@Override
	protected void doOnChange() {
		Proxy proxy = Proxy.load(super.file);
		
		if (proxy.isUseProxy()) {
			System.getProperties().put("proxySet", true);
			System.getProperties().setProperty("http.proxyHost", proxy.getProxyAddress());
			System.getProperties().setProperty("http.proxyPort", proxy.getProxyPort() + "");
		} else {
			System.getProperties().remove("proxySet");
			System.getProperties().remove("http.proxyHost");
			System.getProperties().remove("http.proxyPort");
		}
	}

	@Override
	protected String getFilename() {
		return "proxy.json";
	}
}
